<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <button class="begin">开启定时器</button>
    <button class="stop">停止定时器</button>

</body>

</html>
<script>
    var begin = document.querySelector('.begin');
    var stop1 = document.querySelector('.stop');

    var time = null;
    begin.onclick = function() {
        time = setInterval(function() {
            console.log('你真漂亮');

        }, 2000)
    }

    stop1.onclick = function() {
        // 清除间隔定时器
        clearInterval(time)
    }
</script>